﻿/***************************************************************
 * Name:      http_base.h
 * Purpose:   HTTP协议请求响应基类定义
 * Author:    杨卓荦 (yzl@bang5.net)
 * Created:   2010-08-29
 * Copyright: 杨卓荦 (http://www.bang5.net)
 * License:
 **************************************************************/

#ifndef CLOUDOWN_HTTP_BASE_H_  // 头文件保护开始
#define CLOUDOWN_HTTP_BASE_H_

#include <string>
#include <list>
#include <wx/socket.h>

class HttpBase
{
 public:
  HttpBase();

  virtual ~HttpBase();

  bool SendHttpGetRequest(const char* host,
                          const char* file,
                          const long long int offset,
                          const char* referer);

  bool SendHttpGetRequest(const char* host,
                          const char* file,
                          const char* referer);

  bool SendHttpHeadRequest(const char* host,
                           const char* file,
                           const char* referer);

  int GetBufLine(char *buf, int maxpos, char *line);

  int GetCookieNum() {
    return cookies.size();
  }
  void AddCookie(std::string cookie);
  virtual bool Connect(wxString server, int port);
  virtual bool Connect(std::string server, int port);
  virtual bool Write(const char* buffer, int length);
  virtual int Read(char* buffer, int length);
  virtual void Close();

 protected:
  void MakeRequestBody(char* outbuf, const char* host, const char* referer);

 private:
  std::list<std::string> cookies;
  wxSocketClient socket;
};
#endif  // 头文件保护结束

